'use strict';

const Service = require('egg').Service;

class FollowService extends Service {
    //添加关注
    async create(follow_id,uid) {
        return await this.app.mysql.query('insert into followlist (uid,follow_id) values (?,?)',[uid,follow_id])
    }
    //取消关注
    async destroy(id){
        await this.app.mysql.query('delete from followlist where id=?',[id])
    }
    //查询关注人员的列表
    async index(uid){
        //少一个follow.id
        let follow = await this.app.mysql.query('select f.follow_id,f.id from followlist f where uid=?',[uid]);
        for(let i = 0;i<follow.length;i++){
            let user = await this.app.mysql.query('select u.username from userlist u where id=?',[follow[i].follow_id])
            follow[i].username = user[0].username;
        }
        return follow
    }
    async show(uid,id){
        return await this.app.mysql.query('select * from followlist where uid=? and follow_id=?',[uid,id])
    }
}

module.exports = FollowService;
